﻿using System.Web.UI;
using System.Web.UI.WebControls;

namespace TemplateFoundation.UI.WebControls
{
    /// <summary>
    /// Used to insert a message styled as an EPiServer error message
    /// </summary>
    public class ValidationErrorMessage : Control
    {
        /// <summary>
        /// Gets or sets the error message
        /// </summary>
        public string Text { get; set; }

        /// <summary>
        /// Adds the specified text to a validation summary DIV element
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            Controls.Add(new Literal()
                             {
                                 Text =
                                     string.Format(
                                         "<div class='EP-validationSummary'><ul><li><span class='errormessage'>{0}</span></li></ul><style type='text/css'>span.errormessage {{ color: black !important }}</style></div> ",
                                         Text)
                             });
        }
    }
}
